require('es6-promise').polyfill();
require('es6-promise/auto');
import Vue from 'vue'
import App from './App';
import router from './router'
import store from './store'
// import Axios from 'axios'
import Axios from './utils/axios';
import ElementUI from 'element-ui';
// import 'element-ui/lib/theme-chalk/index.css'
import './../static/css/base.scss';
import './../static/css/reset.css';
import VuePreview from 'vue-preview'
Vue.use(VuePreview)
Vue.use(ElementUI)

Vue.config.productionTip = false;

Vue.prototype.axios= Axios;
import md5 from 'blueimp-md5';
Vue.prototype.MD5 = md5;
router.beforeEach(function (to,from,next) {
  if(store.state.app.loginState.user_id||sessionStorage.getItem('user_id')
      &&sessionStorage.getItem('token')||store.state.app.loginState.token
      &&sessionStorage.getItem('user_name')||store.state.app.loginState.user_name
  ){
      next()
  }else{
    // next()
    if(to.path=='/'){
        next()
    }else{
      next('/')
    }
  }
})

// router.afterEach(function (to,from,next) {
//   if(from.path != '/'&&  to.path == '/'){
//     window.location.reload();
//   }
// })
/* eslint-disable no-new */
var vm =new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
});
window.vm =vm;

